//
//  RootViewController.m
//  Interface
//
//  Created by Letme on 15-4-14.
//  Copyright (c) 2015年 zhenjiea. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.navigationItem.title = @"国外游";
    
    
    self.asiaVC = [[AsiaHomePageViewController alloc] init];
    [self addChildViewController:self.asiaVC];
    [self.view addSubview:self.asiaVC.view];
    [_asiaVC release];
    
    
    
    self.homeVC = [[HomePageViewController alloc] init];
    [self addChildViewController:self.homeVC];
    [self.view addSubview:self.homeVC.view];
    [_homeVC release];
    
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    NSMutableArray *array = [NSMutableArray arrayWithObjects:@"欧洲国家", @"亚洲国家", nil];
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:array];
  
    segment.frame = CGRectMake(38, 10, self.view.frame.size.width - 76, self.view.frame.size.height / 15);
    [segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segment];
    [segment release];
    
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"查询" style:UIBarButtonItemStylePlain target:self action:@selector(BarButtonItemAction:)];
#warning
    self.myView = [[QueryView alloc] initWithFrame:CGRectMake(0, -300, self.view.frame.size.width, 200)];
    [self.view addSubview:self.myView];
#warning
    self.myView.myDelegate = self;
    [_myView release];
} 

- (void)goToSecondViewController:(NSInteger)tag
{
    if (tag == 20001) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"巴黎", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/3/599/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.88266956321907&longitude=121.53966515009307";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
    }
    if (tag == 20002) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"马德里",@"巴塞罗那", nil];
        
        NSString *url1 = @"http://api.breadtrip.com/destination/place/3/24059/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.88265156297574&longitude=121.53968615009308";
        NSString *url2 = @"http://api.breadtrip.com/destination/place/3/81/pois/sights/?start=0&count=20&sort=default&shift=false&latitude=38.88265156297574&longitude=121.53968615009308";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, url2, nil];
        
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        //传数组
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
    }
    if (tag == 20003) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"罗马", @"米兰", @"佛罗伦萨", @"威尼斯", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/3/668/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.88019752980392&longitude=121.5415241500931";
        NSString *url2 = @"http://api.breadtrip.com/destination/place/3/647/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.88019752980392&longitude=121.5415241500931";
        NSString *url3 = @"http://api.breadtrip.com/destination/place/3/667/pois/sights/?start=0&count=20&sort=default&shift=false&latitude=38.88019752980392&longitude=121.5415241500931";
        NSString *url4 = @"http://api.breadtrip.com/destination/place/3/666/pois/sights/?start=0&count=20&sort=default&shift=false&latitude=38.88019752980392&longitude=121.5415241500931";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, url2, url3, url4, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
        
    }
    //英国
    if (tag == 20004) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"伦敦", @"爱丁堡", @"剑桥", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/3/28470/pois/sights/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSString *url2 = @"http://api.breadtrip.com/destination/place/3/1640/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSString *url3 = @"http://api.breadtrip.com/destination/place/3/2274/pois/sights/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        // NSString *url4 = @"http://api.breadtrip.com/destination/place/3/1367/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, url2, url3, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
        
    }
    //德国
    if (tag == 20005) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"柏林", @"慕尼黑", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/3/690/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSString *url2 = @"http://api.breadtrip.com/destination/place/3/465/pois/sights/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, url2, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
        
    }
    //奥地利
    
    if (tag == 20006) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"维也纳", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/3/212/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
    }

    
    
    
    
    if (tag == 20007) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"东京", @"京都", @"大阪", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/2/6/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSString *url2 = @"http://api.breadtrip.com/destination/place/2/3/pois/sights/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSString *url3 = @"http://api.breadtrip.com/destination/place/3/3/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, url2, url3, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
    }
    if (tag == 20008)
    {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"首尔", @"济州", @"釜山", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/3/222/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSString *url2 = @"http://api.breadtrip.com/destination/place/3/7402/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSString *url3 = @"http://api.breadtrip.com/destination/place/3/6975/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, url2, url3, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
    }
    if (tag == 20009) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"伊斯坦布尔", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/3/33611/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
    }
    if (tag == 20010) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"迪拜", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/3/257/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        [self.navigationController pushViewController:secondVC animated:YES];
    }
    if (tag == 20011) {
        NSMutableArray *cityArray = [NSMutableArray arrayWithObjects:@"沙巴", @"仙本那", @"兰卡威", nil];
        NSString *url1 = @"http://api.breadtrip.com/destination/place/2/18/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSString *url2 = @"http://api.breadtrip.com/destination/place/3/23/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        NSString *url3 = @"http://api.breadtrip.com/destination/place/3/9928/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882638562800004&longitude=121.53973415009307";
        
        NSMutableArray *urlArray = [NSMutableArray arrayWithObjects:url1, url2, url3, nil];
        SecondViewController *secondVC = [[SecondViewController alloc] init];
        secondVC.urlArray = urlArray;
        secondVC.cityArray = cityArray;
        NSLog(@"马来西亚");
        [self.navigationController pushViewController:secondVC animated:YES];
        
    }

    
    
}


- (void)BarButtonItemAction:(UIBarButtonItem *)button
{
//    QueryViewController *qVC = [[QueryViewController alloc] init];
//    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:qVC];
//    naVC.navigationBar.translucent = NO;
//    [self presentViewController:naVC animated:YES completion:^{
//        
//        
//    }];
    if (self.isDo == NO) {
        [UIView animateWithDuration:0.5 animations:^{
            self.myView.frame = CGRectMake(0, 0, self.view.frame.size.width, 200);
            
        } completion:^(BOOL finished) {
            
            NSLog(@"第一次点击");
            //[self.view bringSubviewToFront:self.myView];
            
        }];
        self.isDo = YES;
    }else{
        [UIView animateWithDuration:0.5 animations:^{
            self.myView.frame = CGRectMake(0, -300, self.view.frame.size.width, 200);
            
        } completion:^(BOOL finished) {
            
            NSLog(@"第二次点击");
        }];
        self.isDo = NO;
    }

    
}

- (void)segmentAction:(UISegmentedControl *)segment
{
    if (segment.selectedSegmentIndex == 0) {
        [self.view bringSubviewToFront:self.homeVC.view];
    }
    if (segment.selectedSegmentIndex == 1) {
        [self.view bringSubviewToFront:self.asiaVC.view];
    }
#warning
    [self.view bringSubviewToFront:segment];
    [self.view bringSubviewToFront:self.myView];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
